#---------------------------------------------------------
# Are Intermediary Constraints Priced?
# Du, Hébert, Huber
# The Review of Financial Studies 2022
#---------------------------------------------------------

#-----------------------------------------------
# Check and install packages
#-----------------------------------------------

main_pkg <- c('haven', 'readxl', 'zoo', 'gmm', 'xtable', 'lubridate', 'ggplot2', 'data.table', 'reshape2', 'stargazer') 
option_pkg <- c('svMisc', 'dplyr', 'derivmkts', 'lubridate', 'bizdays', 'timeDate', 'mvtnorm', 'lazyeval')
required_pkg <- c(main_pkg, option_pkg)

temp <- installed.packages()
existing_pkg <- temp[, 1]

missing_pkg <- required_pkg[!(required_pkg %in% existing_pkg)]

for (i in missing_pkg) {
  install.packages(i)
}